{template 'web/_header'}
{template 'web/member/tabs'}

{if $operation == 'post'}
<div class="main">
    <form {ife 'member.level' $level}action="" method="post"{/if} class="form-horizontal form" enctype="multipart/form-data">
        <input type="hidden" name="id" value="{$level['id']}" />
        <div class='panel panel-default'>
            <div class='panel-heading'>
                会员等级设置
            </div>
            <div class='panel-body'>
                 <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">等级权重</label>
                    <div class="col-sm-9 col-xs-12">
                        {ife 'member.level' $level}
                        <input type="text" name="level" class="form-control" value="{$level['level']}" />
                        <span class='help-block'>等级权重，数字越大越高级</span>
                        {else}
                        <div class='form-control-static'>{$level['level']}</div>
                        {/if}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 等级名称</label>
                    <div class="col-sm-9 col-xs-12">
                       {ife 'member.level' $level}
                        <input type="text" name="levelname" class="form-control" value="{$level['levelname']}" />
                           {else}
                        <div class='form-control-static'>{$level['levelname']}</div>
                        {/if}
                    </div>
                </div>
                  <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">升级条件</label>
                    <div class="col-sm-9 col-xs-12">
                          {ife 'member.level' $level}
                        <div class='input-group'>
                            <span class='input-group-addon'>订单数量满</span>
                            <input type="text" name="ordercount" class="form-control" value="{$level['ordercount']}" />
                            <span class='input-group-addon'>个 或 订单金额满</span>
                            <input type="text" name="ordermoney" class="form-control" value="{$level['ordermoney']}" />
                            <span class='input-group-addon'>元</span>
                        </div>
                        <span class='help-block'>分销商升级条件，不填写默认为不自动升级</span>
                         {else}
                           <div class='form-control-static'>
                               {if !empty($level['ordercount']) && !empty($level['ordercount'])}
                                 订单数量满: {$level['ordercount']}个 或 订单金额满 {$level['ordercount']} 元 
                               {elseif !empty($level['ordercount'])} 
                                    订单数量满: {$level['ordercount']}个
                               {elseif !empty($level['ordermoney'])}
                                 订单金额满 {$level['ordercount']} 元 
                               {else}
                               不自动升级
                               {/if}
                           
                           </div>
                        {/if}
                    </div>
                </div>
                 <div class="form-group">
                     <label class="col-xs-12 col-sm-3 col-md-2 control-label">折扣</label>
                    <div class="col-sm-9 col-xs-12">
                             {ife 'member.level' $level}
                        <input type="text" name="discount" class="form-control" value="{$level['discount']}" />
                        <span class='help-block'>请输入0.1~10之间的数字,值为空代表不设置折扣</span>
                        {else}
                        <div class='form-control-static'>
                           {if empty($level['discount'])}
                           不打折
                           {else}
                           {$level['discount']}折
                           {/if}
                           </div>
                        {/if}
                    </div>
                </div>
                
                    <div class="form-group"></div>
            <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                    <div class="col-sm-9 col-xs-12">
                           {ife 'member.level' $level}
                            <input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1"  />
                            <input type="hidden" name="token" value="{$_W['token']}" />
                        {/if}
                       <input type="button" name="back" onclick='history.back()' {ifp 'member.level.add|member.level.edit'}style='margin-left:10px;'{/if} value="返回列表" class="btn btn-default" />
                    </div>
            </div>
                
            </div>
        </div>
      
    </form>
</div>
<script language='javascript'>
    $('form').submit(function(){
        if($(':input[name=levelname]').isEmpty()){
            Tip.focus($(':input[name=levelname]'),'请输入等级名称!');
            return false;
        }
        return true;
    })
    </script>
{elseif $operation == 'display'}
               <form action="" method="post" onsubmit="return formcheck(this)">
     <div class='panel panel-default'>
            <div class='panel-heading'>
                会员等级设置
            </div>
         <div class='panel-body'>

            <table class="table">
                <thead>
                    <tr>
                        <th>等级权重</th>
                        <th>等级名称</th>
                        <th>升级条件</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {loop $list $row}
                    <tr>
                        <td>{$row['level']}</td>
                        <td>{$row['levelname']}</td>
                           <td>{if $row['ordercount']>0 && $row['ordermoney']>0}
                              订单满 {$row['ordercount']}个 或 <br/>
                              订单金额满 {$row['ordermoney']}元
                            {else if $row['ordercount']>0}
                            订单满 {$row['ordercount']}个
                            {else if $row['ordermoney']>0}
                            订单金额满 {$row['ordermoney']}元
                            {else}
                            不自动升级
                            {/if}
                          </td>                            
                        <td>
                            {ifp 'member.level.add|member.group.view'}
                            <a class='btn btn-default' href="{php echo $this->createWebUrl('member/level', array('op' => 'post', 'id' => $row['id']))}" title="{ifp 'member.level.edit'}修改{else}查看{/if}"><i class='fa fa-edit'></i></a>
                            {/if}
                             {ifp 'member.level.delete'}
                             <a class='btn btn-default'  href="{php echo $this->createWebUrl('member/level', array('op' => 'delete', 'id' => $row['id']))}" onclick="return confirm('确认删除此等级吗？');return false;"><i class='fa fa-remove'></i></a></td>
                        {/if}

                    </tr>
                    {/loop}
                 
                </tbody>
            </table>
  
         </div>
         {ifp 'member.level.add'}
           <div class='panel-footer'>
                            <a class='btn btn-default' href="{php echo $this->createWebUrl('member/level', array('op' => 'post'))}"><i class="fa fa-plus"></i> 添加新等级</a>
         </div>
         {/if}
     </div>
       </form>
{/if}
{template 'web/_footer'}
